Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Image captioning #48

Merged
merged 37 commits into from
Feb 21, 2017
Merged

Image captioning #48

merged 37 commits into from
Feb 21, 2017

Conversation

szymonkups
Copy link
Contributor

@szymonkups szymonkups commented Feb 2, 2017

Adds captioning feature.
Currently there is no placeholder when caption's nested editable is empty.
There are other issues with nested editables, that will be reported in proper repositories and fixed (keyboard support etc.).
Fixes ckeditor/ckeditor5#5048.

@Reinmar
Copy link
Member

Reinmar commented Feb 7, 2017

Some issues to be resolved in the first place:

  1. There are too few features in the manual test. It's hard to test what happens in the caption. Tere are neither image features loaded, nor other features.
  2. When the selection is inside the nested editable, the widget should not have the focus outline. There can be just one thing focus at a time and, in such situation, it's the nested editable.
  3. See the screenshot – on this branch the image is rendered over the toolbar, when on master it's below:

image

@Reinmar
Copy link
Member

Reinmar commented Feb 7, 2017

And tests fail after I merged master into this branch.

@@ -57,6 +59,13 @@ export function viewToModelImage() {
modelImage.setAttribute( 'alt', viewImg.getAttribute( 'alt' ) );
}

// Convert children of converted view element and append them to `modelImage`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*
* @extends module:core/plugin~Plugin
*/
export default class ImageCaptioning extends Plugin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply: ImageCaption. We have ImageStyles not ImageStyling.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, since this plugin is empty now, you can merge the engine part into it. Unless... unless we see that adding the placeholder will require some strictly UI-related logic.

OTOH, by splitting the feature beforehand we stick to some pattern, so I'm not sure what would be better.

*/
export function captionEditableCreator( viewDocument ) {
return () => {
const editable = new ViewEditableElement( 'figcaption', { contenteditable: true } ) ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space before ;.

* @param {module:engine/view/document~Document} viewDocument
* @return {Function}
*/
export function captionEditableCreator( viewDocument ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editableCaptionCreator()

const captionSymbol = Symbol( 'imageCaption' );

/**
* Returns function that creates caption editable element for given {@link module:engine/view/document~Document}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Returns a function", "for the given"

* @param {module:engine/view/element~Element} viewElement
* @return {Boolean}
*/
export function isCaptionEditable( viewElement ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEditableCaption to pair with the other method. I'm also thinking about isCaption and captionElementCreator. That "editable" part is confusing. Or maybe captionEditableElementCreator? I don't know... :D So maybe let's choose the shortest versions, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll go with captionElementCreator and isCaption - sounds better and it's shorter too.

* @return {module:engine/model/element~Element|null}
*/
export function getCaptionFromImage( imageModelElement ) {
for ( let node of imageModelElement.getChildren() ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be like:

Array.from( imageModelElement.getChildren() ).find( node => node.is( 'caption' ) )

If we do https://github.com/ckeditor/ckeditor5-engine/issues/809.

if ( !isWidget( widgetElement ) ) {
widgetElement = widgetElement.findAncestor( element => isWidget( element ) );
widgetElement = widgetElement.findAncestor( element => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

widgetElement.findAncestor( isWidget );

const widget = editableElement.findAncestor( element => isWidget( element ) );

if ( widget ) {
widget.addClass( WIDGET_SELECTED_CLASS_NAME );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use the I_AM_CONST notation? I don't remember now what we've decided. cc @pjasiun, @scofalik

Copy link
Contributor

@scofalik scofalik Feb 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is complicated :P.
Instead of using stuff like:

const STICKS_TO_PREVIOUS = 0;
const STICKS_TO_NEXT = 1;
...
if ( this.stickiness == STICKS_TO_PREVIOUS ) { ... }

we decided to just use 'sticksToPrevious' string. But this works only for closed list of constant values and was done to get rid of imports.

I don't know whether we decided anything about package-scope/configuration constants like this. If I wrote that code, I'd go with widgetSelectedClassName but I can't say this is wrong either.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see we use the ALL_CAPS notation in some cases. INLINE_FILLER_LENGTH, BR_FILLER, NBSP_FILLER, DEFAULT_PRIORITY. Also, all but one export const use this notation. So let's stick to that.

@pjasiun
Copy link

pjasiun commented Feb 8, 2017

Can't you, instead of createImageAttributeConverter and modelToViewAttributeConverter use model to view conversion builder with fromAttribute( ... ).toAttribute( ... );?

@szymonkups
Copy link
Contributor Author

szymonkups commented Feb 8, 2017

Can't you, instead of createImageAttributeConverter and modelToViewAttributeConverter use model to view conversion builder with fromAttribute( ... ).toAttribute( ... );?

Conversion builder does not allow to specify any information about attribute's element. I don't want to convert all src and alt attributes, only those from image elements.

Reinmar and others added 2 commits February 13, 2017 18:14
@szymonkups
Copy link
Contributor Author

Added caption to limits set in schema, test it further after closing ckeditor/ckeditor5-engine#825.

@Reinmar
Copy link
Member

Reinmar commented Feb 21, 2017

Everything works brilliantly!

@Reinmar
Copy link
Member

Reinmar commented Feb 21, 2017

I'm closing this PR despite the fact that the related tickets in engine and enter packages are still open. Let's not risk some conflicts.

I've spotted two issues with the image caption implementation: #58 and #57.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Image captioning
4 participants